home *** CD-ROM | disk | FTP | other *** search
- Subject: Re: Offscreen bitmaps & switching between two contexts
- Sent: 4/15/96 5:01 PM
- Received: 4/15/96 5:11 PM
- From: Henri Lamiraux, lamiraux@apple.com
- Reply-To: ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- >Greetings,
- >I have created a render class that contains an offscreen bitmap created
- >with the following code:
- >
- > fOffScreenBitmap = FW_NEW(FW_PBitmap,
- > (fOffScreenRect.right.AsInt(),
- > fOffScreenRect.bottom.AsInt(), 0));
- >
- >fOffScreenBitmap is a member variable of my class defined as FW_PBitmap*.
- >
- >I want to be able to create and maintain a FW_CBitmapContext and store it
- >in my class. Then, when I want to render to the offscreen, I'll save the
- >current context and then switch the context to my offscreen bitmap context.
- >
- >FW_CBitmapContext is an auto destruct class and seems to perform its magic
- >(i.e. switch the context etc.) when the class is created. How do I create
- >one of these, save the current context, switch the context and switch the
- >context back once I am done?
- >
- >All of the examples I have seen create this class as a temporary variable
- >immediately before doing their rendering. This is not suitable for what I
- >am trying to accomplish. I need to be able to create the context in the
- >initialize method of my class, set it in other methods of my class and
- >delete it in the destructor of my class.
- >
- >BTW, what is the proper way to dispose of an object created with the FW_NEW
- >macro? Since I only create one instance of the class I currently do a
- >"delete fOffScreenBitmap". Is this the correct way to handle this?
- >
- >Thanks for your help,
- >Nolan Larsen
- >Digital Harbor
-
- 1)
-
- FW_PXXXX object should be defined on the stack. FW_PXXX are already
- pointers (smart pointers). o You should write something like that:
-
- class CMyClass
- {
- public:
- CMyClass();
- virtual ~CMyClass();
- ....
-
- private:
- FW_PBitmap fMyBitmap; // and not FW_PBitmap*. Default constructor
- creates a "NULL" Bitmap
- };
-
-
- CMyClass::CMyClass()
- {
- FW_PBitmap aBitmap(fOffScreenRect.right.AsInt(),
- fOffScreenRect.bottom.AsInt(), 0);
- fMyBitmap = aBitmap;
- }
-
- CMyClass::~CMyClass()
- {
- // Don't do anything. Will automatically delete the bitmap
- }
-
-
- 2)
-
- FW_CBitmapContext should always be created on the stack. Trying to store
- a pointer to a FW_CBitmapContext is a bad idea. Context should only be
- created when needed and released immediatly.
-
- 3)
-
- Using delete to delete objects created with FW_NEW is fine.
-
- .......................................................................
- Henri Lamiraux lamiraux@apple.com
- Apple Computer, Inc. OpenDoc(tm) Development Framework
- .......................................................................
-
-
-